package com.taldh.algorithm.treenode;

import com.taldh.algorithm.base.TreeNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class GetAllElements {

    List<Integer> ans = new ArrayList<>();

    public List<Integer> getAllElements(TreeNode root1, TreeNode root2) {
        midTreeNode(root1);
        midTreeNode(root2);
        ans.sort((Comparator.comparingInt(a -> a)));
        return ans;
    }

    private void midTreeNode(TreeNode root) {
        if (root == null) {
            return;
        }
        if (root.left != null) {
            midTreeNode(root.left);
        }
        ans.add(root.val);
        if (root.right != null) {
            midTreeNode(root.right);
        }
    }

    @Test
    public void test() {
        System.out.println(getAllElements(
                new TreeNode(2,new TreeNode(1), new TreeNode(4)),
                new TreeNode(1,new TreeNode(0), new TreeNode(3))
        ));
    }
}